package com.itheima.demo1;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class ImmutableDemo1 {
    public static void main(String[] args) {

        HashMap<String,String> hm = new HashMap<>();
        hm.put("张三","南京");
        hm.put("李四","北京");
        hm.put("王五","上海");
        hm.put("赵六","北京");
        hm.put("孙七","深圳");
        hm.put("周八","杭州");
        hm.put("吴九","宁波");
        hm.put("郑十","苏州");
        hm.put("刘一","无锡");
        hm.put("陈二","嘉兴");
        hm.put("啊啊啊","111");

        //利用上面获取的数据获取一个不可变的集合

        //获取到所有的键值对对象
        Set<Map.Entry<String, String>> entries = hm.entrySet();

        //将entrySet变成一个数组
        Map.Entry[] arr = new Map.Entry[0];
        Map.Entry[] arr2 = entries.toArray(arr);

        //不可变的Map集合
        Map map = Map.ofEntries(arr2);

        //简化
        Map<Object,Object> map1 = Map.ofEntries(hm.entrySet().toArray( new Map.Entry[0]));

        //最新版 JDK10后的版本

        Map.copyOf(hm);




    }
}
